{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 从位置数据中获取速度\n",
    "\n",
    "在该 notebook 中，你将要用到的数据与你将在本课程的最后一个项目中用到的数据一样。该数据来自如下所示的CSV：\n",
    "\n",
    "| 时间戳  |  位移   |    yaw_rate    | 加速度  |\n",
    "| :--: | :---: | :------------: | :--: |\n",
    "| 0.0  |   0   |      0.0       | 0.0  |\n",
    "| 0.25 |  0.0  |      0.0       | 19.6 |\n",
    "| 0.5  | 1.225 |      0.0       | 19.6 |\n",
    "| 0.75 | 3.675 |      0.0       | 19.6 |\n",
    "| 1.0  | 7.35  |      0.0       | 19.6 |\n",
    "| 1.25 | 12.25 |      0.0       | 0.0  |\n",
    "| 1.5  | 17.15 | -2.82901631903 | 0.0  |\n",
    "| 1.75 | 22.05 | -2.82901631903 | 0.0  |\n",
    "| 2.0  | 26.95 | -2.82901631903 | 0.0  |\n",
    "| 2.25 | 31.85 | -2.82901631903 | 0.0  |"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from helpers import process_data\n",
    "from matplotlib import pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "PARALLEL_PARK_DATA = process_data(\"parallel_park.pickle\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(0.0, 0, 0.0, 0.0),\n",
       " (0.0625, 0.0, 0.0, 1.9600000000000002),\n",
       " (0.125, -0.007656250000000001, 0.0, 1.9600000000000002),\n",
       " (0.1875, -0.022968750000000003, -0.0, 1.9600000000000002),\n",
       " (0.25, -0.045937500000000006, -0.0, 1.9600000000000002)]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# This is what the first few entries in the parallel \n",
    "#   park data look like. \n",
    "\n",
    "PARALLEL_PARK_DATA[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# In this exercise we'll be differentiating (taking the\n",
    "# derivative of) displacement data. This will require \n",
    "# using only the first two columns of this data.\n",
    "timestamps    = [row[0] for row in PARALLEL_PARK_DATA]\n",
    "displacements = [row[1] for row in PARALLEL_PARK_DATA]\n",
    "\n",
    "# You'll use these data in the next lesson on integration\n",
    "# You can ignore them for now.\n",
    "yaw_rates     = [row[2] for row in PARALLEL_PARK_DATA]\n",
    "accelerations = [row[3] for row in PARALLEL_PARK_DATA]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAEWCAYAAABmE+CbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3Xm4XWV59/HvLyHKYTxKgpLDkAAKiiCBA5aLFgURqAwCtRUKDngppS8ISEWDWIsDNYqoRa0tk/IqKFYgoMEGIQjKUEiakDC/SkASQAJyZEiAkNzvH2vtsLKzh3XOHtYefp/r2tfZw9prPXs693qe+xkUEZiZmY0rugBmZtYZHBDMzAxwQDAzs5QDgpmZAQ4IZmaWckAwMzPAAaGlJP2HpH9ucB/vkrSkWWUykHSMpOuKLkeJpCmSQtJ6VR7/rKQL82zbKSR9RNJvM7dD0vY5nte273t5Gcse66jvSLs4IIyRpIclrZD0nKQRSbdKOkHSmvc0Ik6IiC8VWc5OI+nXkj7W4mPcI+n59LJK0ouZ25+NiEsj4oBWlqGZIuJfI6Lh90zSWZJWpu9D6Tu7VzPK2C5pYHkhfQ1LJX1D0vhmH6fbviPN4oDQmEMjYmNgG2AG8BngomKLZBGxU0RsFBEbAb8BTirdjoh/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rkvvXwTsm17fH3hrOm0BwCaSNk7XYyjZgmQq4ZJbgG9IuhS4MiKWpAHhAGB+us1GJAHi7cDPSguvRERpDYu9gCPT6z8EvpbZ/8yIWA3cK+kN6X37AD+OiFXAY5LmpPc/C7wIXJjWHLLTYjxJElTMcnOTkfWqlzLXV2dur+bVE6FxwF4RsWt6GSoLBgArgPVLNyJiBvAxYAC4XdKOJLWCr2T2s306t5TIN9V6dptsuVVlm1JZXiGplVxBUsPIzsGzflp2s9wcEKyfXQecVLohadcK29wHbJ/ZZruIWBQRXyVpltmRpKnpo2kTEpKGJG0O3AD8naTN0vtLTUa3kswWCnAMydKatdwMHJUutrMFaQ0nPd6m6QSAp5Im21Nvpstn7bT2c5OR9bOTge9KWkjyW7gZOCG7QUTcL2nTTFPSqZL2BVaRtOX/MiJekvQW4La0+el54NiIuEfS2cBNklaRNCl9JD3uxZJOJ2mOqtdF9CpgP5LmrgeBm9L7NwaulrQ+SW3ik5nn7A18AbNR8GynZnVI+iTwXER0zFiEWiRNA06LiA8WXRbrLm4yMqvve6zdtt/pJgL/XHQhrPu4hmBmZoBrCGZmlnJAMDMzwAHBzMxSDghmZgY4IJiZWer/A7hfI5QF84E4AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.title(\"Displacement vs Time while Parallel Parking\")\n",
    "plt.xlabel(\"Time (seconds)\")\n",
    "plt.ylabel(\"Displacement (meters)\")\n",
    "plt.scatter(timestamps, displacements)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在上图中，你可以看到车辆平行停车时的位移与时间数据。请注意，如果汽车向后运动，里程表会出现回落，且位移减小（这实际上并不是里程表对现代汽车的工作原理。抱歉，翘课天才）\n",
    "\n",
    "请注意，大约有4秒钟，汽车是向后移动的，然后在最后2秒，又向前移动。\n",
    "\n",
    "让我们看一看这个轨迹中间的某些数据。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1.25, 1.3125]\n",
      "[-1.4087500000000004, -1.5312500000000004]\n"
     ]
    }
   ],
   "source": [
    "print(timestamps[20:22])\n",
    "print(displacements[20:22])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "所以你可以看到，在 $t=1.25$ 时，汽车的位移是 $x=-1.40875$；在 $t=1.3125$时，汽车的位移是  $x=-1.53125$ 。\n",
    "\n",
    "这意味着，我们可以按照如下公式计算速度/斜率：\n",
    "\n",
    "$$\\text{slope} = \\frac{\\text{vertical change}}{\\text{horizontal change}} = \\frac{\\Delta x}{\\Delta t}$$\n",
    "\n",
    "套入刚才提到的数字，即：\n",
    "\n",
    "$$\\frac{\\Delta x}{\\Delta t} = \\frac{-1.53125 - -1.40875}{1.3125 - 1.25} = \\frac{-0.1225 \\text{ meters}}{0.0625\\text{ seconds}} = -1.96 \\frac{m}{s}$$\n",
    "\n",
    "所以我可以得出如下结论：\n",
    "\n",
    "> 在$t=1.25$ 和 $t=1.3125$ 之间，车辆的**平均速度**为**-1.96 米/每秒**\n",
    "\n",
    "我可以用下面的代码进行相同的计算："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-1.9600000000000009\n"
     ]
    }
   ],
   "source": [
    "delta_x = displacements[21] - displacements[20]\n",
    "delta_t = timestamps[21] - timestamps[20]\n",
    "slope   = delta_x / delta_t\n",
    "\n",
    "print(slope)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "本课刚开始时，你使用的是真正连续的函数。在那种情况下，你可以将 $\\Delta t$ 尽可能小！\n",
    "\n",
    "但是现在我们有了真实的数据，这意味着$\\Delta t$ 的大小取决于我们对位移进行测量的频率。在这个下，案例中似乎后续的测量被分开了\n",
    "\n",
    "$$\\Delta t = 0.0625 \\text{ seconds}$$\n",
    "\n",
    "在下面的`get_derivative_from_data`函数中，我演示了如何“获取真实数据的导数”。仔细阅读这些代码并理解它的工作原理：在下一个notebook中，你需要亲自重新编写此代码。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAEWCAYAAABmE+CbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3XmcXGWd7/HPN6EhjSwBCQodQhAQ3BNoFwwiIAIqaoTBFXcHneuCjKIw3rngHbgygwMuuHEBQRGUC4i8QNkEEkFREhPWgMMgmASQoEaIRCHhd/84T4VDW11dna6qs9T3/Xr1K7WcOudX3ZX6ned5fud5FBGYmZlNKjoAMzMrBycEMzMDnBDMzCxxQjAzM8AJwczMEicEMzMDnBBsFJKuk/ShAo//E0nvLer4I0k6TtI5LZ6/XdLe7WxbFvm/saT3Sbq+zdedJen47ka37lijfg7L9hmpAyeEkpG0p6SfS/qzpD9KukHSS4uOq5MkvUrSqvTzF0mRu79K0oyIeF1EnF10rO2KiBdExHUT3Y+keyWtTr+H30v6tqRNOhBiT6TEsjbF/4ikxZIO6saxqvYZqQInhBKRtBlwKfBVYEtgCPg88Lci4+q0iPhZRGwSEZsAL0gPT208FhG/KzK+Enhj+t3sBrwU+J/j3YGkDToeVft+keKfCpwBnC9py/HsQBl/P/WYf+Hl8lyAiDgvItZGxOqIuDIiboF1Z183SPpqakHcKek1jRdL2lzSGZIekLRc0vGSJuee/4CkJZL+JOkKSdvnnntt2t+fJZ0KqFmAkrZNZ7Bb5h6bLelhSQOSdpI0L+3nYUk/WJ9fRJPujBsknSJppaR7JL0yPb5U0kP5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2ZXsq6mD6QuJCQNSdoa+CnwVknPTI83uox+TjZjKMC7yJbYbGU+8Pa06M42pBZOOt7maSLAT5IG25PnUvFZO6333GVk/ewTwNck3UL2f2E+8JH8BhFxp6TNc11Jn5S0D7CWrC//JxHxN0nPA36Rup9WAYdFxO2STgDmSVpL1qX0vnTcMyUdRdYdNVaJ6A+Bfcm6u34DzEuPbwr8SNIUstbEkbnXzAE+j9k4eLZTszFIOhJ4NCJKcy1CK5JmA/8cEe8uOharFncZmY3tGzy9b7/stgL+teggrHrcQjAzM8AtBDMzS5wQzMwMcEIwM7PECcHMzAAnBDMzS/4/faKDC/yyDk8AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def get_derivative_from_data(position_data, time_data):\n",
    "    \"\"\"\n",
    "    Calculates a list of speeds from position_data and \n",
    "    time_data.\n",
    "    \n",
    "    Arguments:\n",
    "      position_data - a list of values corresponding to \n",
    "        vehicle position\n",
    " \n",
    "      time_data     - a list of values (equal in length to\n",
    "        position_data) which give timestamps for each \n",
    "        position measurement\n",
    "    \n",
    "    Returns:\n",
    "      speeds        - a list of values (which is shorter \n",
    "        by ONE than the input lists) of speeds.\n",
    "    \"\"\"\n",
    "    # 1. Check to make sure the input lists have same length\n",
    "    if len(position_data) != len(time_data):\n",
    "        raise(ValueError, \"Data sets must have same length\")\n",
    "    \n",
    "    # 2. Prepare empty list of speeds\n",
    "    speeds = []\n",
    "    \n",
    "    # 3. Get first values for position and time\n",
    "    previous_position = position_data[0]\n",
    "    previous_time     = time_data[0]\n",
    "    \n",
    "    # 4. Begin loop through all data EXCEPT first entry\n",
    "    for i in range(1, len(position_data)):\n",
    "        \n",
    "        # 5. get position and time data for this timestamp\n",
    "        position = position_data[i]\n",
    "        time     = time_data[i]\n",
    "        \n",
    "        # 6. Calculate delta_x and delta_t\n",
    "        delta_x = position - previous_position\n",
    "        delta_t = time - previous_time\n",
    "        \n",
    "        # 7. Speed is slope. Calculate it and append to list\n",
    "        speed = delta_x / delta_t\n",
    "        speeds.append(speed)\n",
    "        \n",
    "        # 8. Update values for next iteration of the loop.\n",
    "        previous_position = position\n",
    "        previous_time     = time\n",
    "    \n",
    "    return speeds\n",
    "\n",
    "# 9. Call this function with appropriate arguments\n",
    "speeds = get_derivative_from_data(displacements, timestamps)\n",
    "\n",
    "# 10. Prepare labels for a plot\n",
    "plt.title(\"Speed vs Time while Parallel Parking\")\n",
    "plt.xlabel(\"Time (seconds)\")\n",
    "plt.ylabel(\"Speed (m / s)\")\n",
    "\n",
    "# 11. Make the plot! Note the slicing of timestamps!\n",
    "plt.scatter(timestamps[1:], speeds)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "现在你已经阅读了该代码并了解了它的使用方式（以及结果图的大致轮廓），接下来，我想说一下代码的数字部分。\n",
    "\n",
    "1. 时间与位置数据需要具有相同的长度，因为每个位置测量都与这些时间戳中的一个值相对应。\n",
    "\n",
    "2. `speeds`列表最终将在函数运行结束时返回。\n",
    "\n",
    "3. 在这些变量名称中使用的“previous”这个词，你会在步骤8中更清楚地知道它的含义。但是如果我们要计算一个 delta X，基本上我们需要两个位置数据。这就是我们在position_data列表中抓取的第一个位置的位置。\n",
    "\n",
    "4. 需要注意的是，我们从范围`range(1, len(position_data))`开始循环，这意味着 `i`的第一个值是`1`而**不是**`0`。这是因为我们已经在步骤3中获取了元素0。\n",
    "\n",
    "5. 获取这个`i`的数据。\n",
    "\n",
    "6. 计算位置和时间的变化。\n",
    "\n",
    "7. 找到斜率（即速度）并将其追加到`speeds`列表中。\n",
    "\n",
    "8. 设置`previous_position`和`previous_time`的值，这样便于它们对此循环的*下一次* 迭代也是正确的。\n",
    "\n",
    "9. 在这里，我们通过利用之前使用过的`displacements`和`timestamps`数据来调用该函数。\n",
    "\n",
    "10. 自解释。\n",
    "\n",
    "11. 这部分很有趣。需要注意的是，我们只绘制`timestamps[1:]`。这就是说，“除了第一个元素之外的`timestamps`中的每个元素”。请牢记，在第4步中，除了第一个元素外，我们是如何进行循环的？也就是说，我们的`speeds`数组最终比原始数据短1个元素。\n",
    "\n",
    "## 你要牢记的内容\n",
    "上面所有这些内容，你都不需要记住，重要的是要记住下面这一点：\n",
    "\n",
    "在处理实时时间序列数据时，可以通过查找相邻数据点之间的斜率来计算“导数”。\n",
    "\n",
    "在下一个 notebook 中，你将需要亲自尝试做这些任务 。如果需要帮助，请随时回到这里，但请尽量自己尝试解决遇到的问题。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
